package json;

import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;

import java.io.File;
import java.nio.charset.Charset;

/**
 * @Description 省份
 * @Author hhy
 * @Date 2020/10/21 15:30
 */
public class Province {

    public static String getProvinceByCity(String city){
        if (city.length()<2) return null;
        //从json文件中来拿到json对象

        JSONObject jsonObject = JSONUtil.readJSONObject(new File("Mycity.json"), Charset.forName("UTF-8"));
        for (String s : jsonObject.keySet()) {
            JSONArray jsonArray = jsonObject.getJSONArray(s);
            for (int i = 0; i < jsonArray.size(); i++) {
                if (jsonArray.getStr(i).contains(city)){
                    return s;
                }
            }
        }
        return null;
    }

}
